package cn.tedu.lbs.basic.web.controller;

import cn.tedu.lbs.basic.web.service.AdminService;
import cn.tedu.lbs.basic.web.util.AuthenticationContextUtil;
import com.tarena.lbs.base.common.utils.Asserts;
import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.common.passport.encoder.JwtEncoder;
import com.tarena.lbs.common.passport.principle.UserPrinciple;
import com.tarena.lbs.pojo.basic.vo.AdminVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@RestController
public class AdminController {
    @Autowired
    private AdminService adminService;
    @Autowired
    private JwtEncoder<UserPrinciple> jwtEncoder;
    @GetMapping("/admin/basic/role/detail")
    public Result<AdminVO> detail() throws BusinessException {
        //下游代码 直接从工具拿到上游 解析参数
        UserPrinciple userPrinciple = AuthenticationContextUtil.get();
        //断言 一旦是空 异常结束
        Asserts.isTrue(userPrinciple==null,new BusinessException("-2","用户认证解析失败"));
        AdminVO vo=adminService.detail(userPrinciple.getId());
        return new Result<>(vo);
    }
}
